package com.ocom.webapi.controller;

import com.ocom.common.constant.AccessServiceUrl;
import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.request.web.StaffPageDeleteRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.common.utils.poi.ExcelUtil;
import com.ocom.webapi.feign.AccessClientService;
import com.ocom.webapi.feign.HumanClientService;
import com.ocom.webapi.service.StaffPageService;
import com.ocom.webapi.vo.staffpage.ImportVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;


@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class StaffPageController {

	@Autowired
	AccessClientService accessClientService;

	@Autowired
	HumanClientService humanClientService;

	@Autowired
	private StaffPageService staffPageService;

	@PostMapping(WebApiServiceUrl.URLP_StaffPageDelete)
	public Result delete(@Valid  @RequestBody  StaffPageDeleteRequest request){
	//	System.out.println("StaffPageDeleteRequest:"+request.toString());
		Result result = humanClientService.removePerson(request.getComId(),0L,request.getPId());
		if(result.getCode()!=200){
			return ResultUtil.error(result.getCode());
		}
		//移除白名单
		accessClientService.clearAccessByUser(request.getComId(),0L,request.getPId());
		return ResultUtil.success();

	}




    /**
	 * 导入人员（StaffPage/import）
	 * */
	@PostMapping(WebApiServiceUrl.URL_StaffPageImport)
	public Result StaffPageImport( Long comId,String areaGroop,@RequestPart("file") MultipartFile file){
		return  staffPageService.StaffPageImport(comId,areaGroop,file);
	}
}
